'use strict'
/**
 * 合同通用操作服务类
 */
define(function (require, exports, module) {
    var angular = require('angular');
    var util = require('@yunke/core/util').default;
    var api_prefix = G_CONFIG["api_prefix"]; //api前缀

    var AbnormalCommon = angular.module('AbnormalCommonService', []);

    AbnormalCommon.service('abnormalCommonService', ['$rootScope', function ($rootScope) {
        var service = {
            
            getContractAreas: function (callback) {
                /**
                 * 获取合同区域列表
                 */
                var get_data = {};
                var url = api_prefix + "/contract/get-contract-area-list";
                this.ajax('合同区域', url, get_data, callback);
            },
            getCompanies: function (callback) {
                /**
                 * 获取公司列表
                 */
                var get_data = {};
                var url = api_prefix + "/erp-interface/get-companies";
                this.ajax('公司', url, get_data, callback, 'GET', false);
            },
            
            ajax: function (title, url, get_data, callback) {
                util.myAjax({
                    url: url,
                    type: "GET",
                    context: this,
                    data: get_data,
                    success: function (json) {
                        if (json.retCode === "0") {
                            callback && callback(json.data);
                        } else {
                            util.alert("获取" + title + "失败：" + json.errMsg);
                        }
                    }
                });
            }
        }
        return service;
    }]);

    module.exports = AbnormalCommon;
});